package com.lc.cehui.util;

import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.RelativeSizeSpan;
import android.view.View;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;

import java.util.List;

public class SuperUtil {

    //控件隐藏显示
    public static void setVisibility(View view, boolean b) {
        if (b) {
            view.setVisibility(View.VISIBLE);
        } else {
            view.setVisibility(View.GONE);
        }
    }

    //判断是否是空的TextView,如果是空的提示输入
    public static boolean isEmptyText(TextView textView) {
        if (textView.getText().toString().equals("")) {
            ToastUtils.showShort(textView.getHint().toString());
            return true;
        }
        return false;
    }
    public static boolean isEmptyTextNoToast(TextView textView) {
        if (textView.getText().toString().equals("")) {
            return true;
        }
        return false;
    }

    //获取TextView文字
    public static String getText(TextView textView) {
        return textView.getText().toString();
    }

    //手机号隐藏中间部分
    public static String concealPhoneNumber(String phoneNumber) {
        phoneNumber.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
        return phoneNumber;
    }

    //截取首尾
    public static String removeHeadTail(String str) {
        return str.substring(1, str.length() - 1);
    }

    //格式化文字 首尾缩小 中间放大
    public static SpannableString changFirstSize(String value) {
        SpannableString spannableString = new SpannableString(value);
        spannableString.setSpan(new RelativeSizeSpan(1.7f), 1, value.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spannableString;
    }

    //格式化格式化文字 价格样式.后面缩小
    public static SpannableString changTVsize(String value) {
        SpannableString spannableString = new SpannableString(value);
        if (value.contains(".")) {
            spannableString.setSpan(new RelativeSizeSpan(0.7f), value.indexOf("."), value.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        return spannableString;
    }

    //取小数点后两位
    public static String decimal(Float f) {
        return String.format("%.2f", f);
    }


}
